package com.qhs.framework.utils;



import com.qhs.framework.base.BaseModel;
import com.qhs.framework.config.shiro.ShiroManager;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 *
 * @author zhangqing
 * @date 2017年03月07日
 */
public class ModelUtil {


    private static IDWorker idWorker = new IDWorker();

    /**
     * 增加操作的时候,调用当前方法,对共用字段(createBy和createDate)进行初始化
     * @param baseModel
     */
    public static void insertInit(BaseModel baseModel) {
        if(HelpUtils.isNotEmpty(baseModel)){
            Long ss =ShiroManager.getLoginId();
            baseModel.setCreateBy(ShiroManager.getLoginId());
            baseModel.setCreateTime(DateUtil.getDefaultDate());
            baseModel.setActiveFlag(1);
            /* 主键处理 */
            if (HelpUtils.isEmpty(baseModel.getId())) {
                baseModel.setId(idWorker.generateId());
            }
        }
    }


    /**
     * 修改操作的时候,调用当前方法,对共用字段(updateBy和updateDate)进行修改
     * @param baseModel
     */
    public static void updateInit(BaseModel baseModel) {
        if(HelpUtils.isNotEmpty(baseModel)){
            baseModel.setUpdateBy(ShiroManager.getLoginId());
            baseModel.setUpdateTime(DateUtil.getDefaultDate());
        }
    }
}
